/*
 *  connection.h - Connection management functions
 *  Copyright (c) 2005 Derek Ingrouville (dergro@users.sourceforge.net)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef _CONNECTION_H
#define _CONNECTION_H

typedef struct _MsnConnection MsnConnection;

#include "socket.h"
#include "cbtable.h"
#include "message.h"
#include "events.h"
#include "session.h"

typedef void (*MsnConnCB)(MsnConnection *conn);

struct _MsnConnection
{
    Socket *socket;
    MsnSession *session;
    GIOChannel *channel;
    unsigned int trid;
    MsnConnCB connect_cb;
    MsnConnCB disconnect_cb;
    MsnCallbacks *callbacks;
    MsnEventQueue *events;
    gboolean connected;
};

MsnConnection *msn_connection_new (MsnSession *session);
void msn_connection_free (MsnConnection *conn);

int msn_connection_connect (MsnConnection *conn, const char *server, unsigned int port);
void msn_connection_disconnect (MsnConnection *conn);

int msn_connection_send_cmd (MsnConnection *conn, const char *format, ...);
int msn_connection_read (MsnConnection *conn, char *dest_buf, unsigned int size);
MsnCommand *msn_connection_recv_cmd (MsnConnection *conn);
MsnMessage *msn_connection_recv_msg (MsnConnection *conn, char *header);

void msn_connection_set_connect_cb (MsnConnection *conn, MsnConnCB connect_cb);
void msn_connection_set_disconnect_cb (MsnConnection *conn, MsnConnCB disconnect_cb);

gboolean msn_data_available (MsnConnection *conn);

#endif /* _MSNDATA_H */
